$(function () {
    //采购方公司加载
    $("#bzjlxfp_gs_id").ssgsjgcombotree();
    //客户加载
    $("#bzjlxfp_kh_id").qyjgzcombobox();

    $("#grid_bzjlxfp").datagrid({
        url: $.webPath() + "/report/bzjlxfp/bzjlxfpList",
        toolbar: "#toolbar_bzjlxfp",
        fitColumns: true,
        singleSelect: true,
        fit: true,
        pageNumber: 1,
        showFooter:true,
        striped: true,
        pagination: true,
        rownumbers: true,
        columns: [
            [
                {field: 'gs', title: '园区', align: 'center', width: 110},
                {field: 'kh', title: '客户', align: 'center', width: 110},
                {field: 'htbm', title: '合同', align: 'center', width: 110},
                {field: 'bzj', title: '保证金', align: 'center', width: 100, formatter: function (value) {
                    var val = formatJeForHtml2(value);
                    return val;
                }},
                {field: 'zlx', title: '总利息', align: 'center', width: 100, formatter: function (value) {
                    var val = formatJeForHtml2(value);
                    return val;
                }},
                {field: 'ysy', title: '使用利息', align: 'right', width: 150, formatter: function (v, r, i) {
                    var color = "#0000ff;";
                    if (v && v > 0 && r.gs != '合计') {
                        return '<a href="javascript:void(0)" style="color:' + color + '" class="bzjlxfp" khid="'+ r.khid+'" htbm="'+ r.htbm+'" gsid="' + r.gsid + '">' + formatJeForHtml2(v) + '</a>';
                    } else {
                        return formatJeForHtml2(v);
                    }
                }},
                {field: 'sy', title: '利息剩余', width: 150, align: 'right', formatter: function (value) {
                    var val = formatJeForHtml2(value);
                    return val;
                }}
            ]
        ],
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
            $(".bzjlxfp").unbind("click").bind("click", function () {
                var win = $.window({
                    title: "保证金利息使用明细",
                    width: 800,
                    height: 500,
                    maximizable: true,
                    cache: false,
                    iconCls: 'icon-tip',
                    url: $.webPath() + "/report/bzjlxfp/bzjlxfp_detail?gsId="+$(this).attr("gsid")+"&khId="+$(this).attr("khid") + "&htbm=" + $(this).attr("htbm"),
                    modal: true,
                    buttons: [],
                    onMaximize: function () {
                        $(this).find("#bzjlxfp_detail_grid").edatagrid("resize");
                    },
                    onRestore: function () {
                        $(this).find("#bzjlxfp_detail_grid").edatagrid("resize");
                    }
                });
            });
        }
    });

    $("#toolbar_bzjlxfp a[name='dc']").click(function(){
        var khId = $('#toolbar_bzjlxfp [name="bzjlxfp.kh.id"]').val() || '';
        window.open($.webPath() + "/report/bzjlxfp/export?gsId=" + $('#toolbar_bzjlxfp [name="bzjlxfp.gs.id"]').val() +
            "&khId=" + khId  +
            "&htbm=" + $("#bzjlxfp_ht").val() || '');
    });

    $("#btn_bzjlxfp_search").click(function () {
        $('#grid_bzjlxfp').datagrid('load',
            {
                gsId:$('#toolbar_bzjlxfp [name="bzjlxfp.gs.id"]').val(),
                khId:$('#toolbar_bzjlxfp [name="bzjlxfp.kh.id"]').val(),
                htbm:$("#bzjlxfp_ht").val()
            }
        );
    });
});
